'''作业1：定义一个分数类'''


class Fraction(object):
    def __init__(self, num, den):
        '''

        :param num: 分子
        :param den: 分母
        '''
        self._num = num;
        self._den = den;

    def __getNum__(self):
        return self._num;

    def __getDen__(self):
        return self._den;

    def __show__(self):
        print('%d/%d' % (self._num, self._den));

    def simple(self):
        x = self.gcd(self._num, self._den)
        self._num /= x;
        self._den /= x;

    def gcd(self, a, b):
        return a if b == 0 else self.gcd(b, a % b);

    def __add__(self, other):
        newnum = self._num * other._den + self._den * other._num;
        newdem = self._den * other._den;
        Neww = Fraction(newnum, newdem)
        Neww.simple()
        return Neww

    def __sub__(self, other):
        newnum = self._num * other._den - self._den * other._num;
        newdem = self._den * other._den;
        Neww = Fraction(newnum, newdem)
        Neww.simple()
        return Neww

    def __mul__(self, other):
        newnum = self._num * other._num;
        newdem = self._den * other._den;
        Neww = Fraction(newnum, newdem)
        Neww.simple()
        return Neww

    def __truediv__(self, other):
        if other._num == 0:
            print('无法进行除法')
            Neww = Fraction(999999, 1)
        else:
            newnum = self._num * other._den;
            newdem = self._den * other._num;
            Neww = Fraction(newnum, newdem)
        Neww.simple()
        return Neww

    def __str__(self):
        return str(str(self._num) + '/' + str(self._den))

    def __gt__(self, other):
        if self._num * other._den > self._den * other._num:
            print('%s 是更大的' % self.__str__())
        else:
            print('%s 不是更大的' % self.__str__())

    def __ge__(self, other):
        if self._num * other._den >= self._den * other._num:
            print('%s 是更大或者相等' % self.__str__())
        else:
            print('%s 不是更大或者相等' % self.__str__())

    def __lt__(self, other):
        if self._num * other._den < self._den * other._num:
            print('%s 是小的' % self.__str__())
        else:
            print('%s 不是小的' % self.__str__())

    def __le__(self, other):
        if self._num * other._den <= self._den * other._num:
            print('%s 是小的或者相等' % self.__str__())
        else:
            print('%s 不是小的或者相等' % self.__str__())

    def __ne__(self, other):
        if self._num * other._den == self._den * other._num:
            print('%s 是相等' % self.__str__())
        else:
            print('%s 不是者相等' % self.__str__())


def main():
    '''测试第一题
    :return:
    '''
    fra = Fraction(3, 4)
    print(fra.__getNum__())
    print(fra.__getDen__())

    '''测试第二题和第三题'''
    fra1 = Fraction(1, 2)
    fra2 = Fraction(4, 6)
    fra1.__add__(fra2).__show__()
    fra1.__sub__(fra2).__show__()
    fra1.__mul__(fra2).__show__()
    fra1.__truediv__(fra2).__show__()

    '''测试第四题'''
    fra1.__gt__(fra2)
    fra1.__ge__(fra2)
    fra1.__lt__(fra2)
    fra1.__le__(fra2)
    fra1.__ne__(fra2)


if __name__ == '__main__':
    main();

